home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / master / Examples / Printer_Driver / transfer.c < prev   
C/C++ Source or Header  |  1994-02-01  |  3KB  |  132 lines

  1.  
  2. /*
  3.  *  TRANSFER.C
  4.  *
  5.  *  David Berezowski - March/88.
  6.  *  Modified for DICE - May/91    Matthew Dillon
  7.  *
  8.  *  Copyright (c) 1988    Commodore-Amiga, Inc.
  9.  *  (c)Copyright 1991 Matthew Dillon
  10.  */
  11.  
  12. #include "defs.h"
  13.  
  14. Prototype void Transfer(PrtInfo *, UWORD, UBYTE *, UWORD *);
  15.  
  16. void
  17. Transfer(PInfo, y, ptr, colors)
  18. PrtInfo *PInfo;
  19. UWORD y;        /* row # */
  20. UBYTE *ptr;        /* ptr to buffer */
  21. UWORD *colors;        /* indexes to color buffers */
  22. {
  23.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  24.     union colorEntry *ColorInt;
  25.     UBYTE *yptr, *mptr, *cptr, Black, Yellow, Magenta, Cyan;
  26.     UBYTE *dmatrix, dvalue, threshold;
  27.     UWORD *sxptr, bit, x3, ymod;
  28.     register UWORD x, sx, width;
  29.     register UBYTE *bptr;
  30.  
  31.     /* pre-compute */
  32.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  33.  
  34.     x = PInfo->pi_xpos;
  35.     ColorInt = PInfo->pi_ColorInt;
  36.     sxptr = PInfo->pi_ScaleX;
  37.     width = PInfo->pi_width;
  38.  
  39.     /* printer specific */
  40.  
  41.     x3 = x * 3;
  42.     ymod = y % PED->ped_NumRows;
  43.     bit = bit_table[ymod & 7];
  44.     ptr += ymod >> 3;
  45.     bptr = ptr + colors[0];
  46.     yptr = ptr + colors[1];
  47.     mptr = ptr + colors[2];
  48.     cptr = ptr + colors[3];
  49.  
  50.     /* pre-compute threshold; are we thresholding? */
  51.  
  52.     if (threshold = PInfo->pi_threshold) { /* thresholding */
  53.     dvalue = threshold ^ 15;
  54.     bptr += x3;
  55.  
  56.     /* for all source pixels */
  57.  
  58.     do {
  59.         /* pre-compute intensity values for each component */
  60.         Black = ColorInt->colorByte[PCMBLACK];
  61.         ColorInt++;
  62.  
  63.         sx = *sxptr++;
  64.  
  65.         /* use this pixel 'sx' times */
  66.         do {
  67.         if (Black > dvalue)
  68.             *bptr |= bit;
  69.         bptr += 3;
  70.         } while (--sx);
  71.     } while (--width);
  72.     } else {
  73.     /* not thresholding, pre-compute ptr to dither matrix */
  74.  
  75.     dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  76.     if (PD->pd_Preferences.PrintShade == SHADE_GREYSCALE) {
  77.         bptr += x3;
  78.  
  79.         /* for all source pixels */
  80.         do {
  81.         /* compute intensity val for each component */
  82.         Black = ColorInt->colorByte[PCMBLACK];
  83.         ColorInt++;
  84.  
  85.         sx = *sxptr++;
  86.  
  87.         /* use this pixel 'sx' times */
  88.         do {
  89.             if (Black > dmatrix[x & 3])
  90.             *bptr |= bit;
  91.             x++; /* done 1 more printer pixel */
  92.             bptr += 3;
  93.         } while (--sx);
  94.         } while (--width);
  95.     } else {                /* color */
  96.         /* for all source pixels */
  97.         do {
  98.         /* compute intensity val for each component */
  99.         Black = ColorInt->colorByte[PCMBLACK];
  100.         Yellow = ColorInt->colorByte[PCMYELLOW];
  101.         Magenta = ColorInt->colorByte[PCMMAGENTA];
  102.         Cyan = ColorInt->colorByte[PCMCYAN];
  103.         ColorInt++;
  104.  
  105.         sx = *sxptr++;
  106.  
  107.         /* use this pixel 'sx' times */
  108.         do {
  109.             dvalue = dmatrix[x & 3];
  110.             if (Black > dvalue) {
  111.             *(bptr + x3) |= bit;
  112.             } else  {            /* black not rendered */
  113.             if (Yellow > dvalue) {
  114.                 *(yptr + x3) |= bit;
  115.             }
  116.             if (Magenta > dvalue) {
  117.                 *(mptr + x3) |= bit;
  118.             }
  119.             if (Cyan > dvalue) {
  120.                 *(cptr + x3) |= bit;
  121.             }
  122.             }
  123.             ++x;    /* done 1 more printer pixel */
  124.             x3 += 3;
  125.         } while (--sx);
  126.         } while (--width);
  127.     }
  128.     }
  129. }
  130.  
  131.  
  132.